/**
 * 
 */
package com.shiplanet.dao.impl;

import java.util.List;

import org.hibernate.Query;
import org.springframework.stereotype.Repository;

import com.shiplanet.dao.CategoryDAO;
import com.shiplanet.entity.Category;

/**
 * @author joesong
 *
 */
@Repository("categoryDAO")
public class CategoryDAOImpl extends BaseDAOImpl<Category> implements
		CategoryDAO {

	public List<Category> findPopularCategories() {
		return find("from Category as c where c.isPopular = true");
	}

	public List<Category> findRootCategories() {
		return find("from Category as c where c.parent is null order by c.name");
	}

	public void removePostsByCategory(List<Category> categoryList) {
		Query q = this
				.getCurrentSession()
				.createQuery(
						"Update Post as p set p.category = null where p.category in (:catList)")
				.setParameterList("catList", categoryList);
		q.executeUpdate();
	}
}
